package org.zjz.fun.batWord

import com.google.common.base.Preconditions
import org.apache.poi.xwpf.usermodel.XWPFParagraph
import org.zjz.emu.WordType
import org.zjz.emu.WordType.WordType

object PreconditionFun {
  /**
   * 根据自定义的判断依据，对word中划分文档经行区别
   * @param pre
   * @param paragraph
   * @return  是否符合判断的依据
   */
  def fun(pre: String, paragraph: XWPFParagraph): Boolean = {
    Preconditions.checkNotNull(pre)
    Preconditions.checkNotNull(paragraph)
    var typeArray = pre.split("#")
    var size: Int = 0
    var wType: WordType = null
    try {
      size = typeArray(1).toInt
      wType = WordType.withName(typeArray(0).toLowerCase)
    } catch {
      case ex: NoSuchElementException => println(s"type is ${WordType.values.mkString(",")}")
      case ex: NumberFormatException => ex.printStackTrace()
    }
    wType match {
      case WordType.FONT_SIZE =>{
        Preconditions.checkNotNull(size,"%S","fontsize#123")
        size==paragraph.createRun().getFontSize
      }
      case WordType.TEXT => pre == paragraph.getText
      case WordType.BOLD => paragraph.createRun().isBold
    }
  }
}
